package com.dts.yjnb.service.controller.user;

import com.dts.common.core.domain.AjaxResult;
import com.dts.common.core.domain.AppResponse;
import com.dts.common.core.page.AppPageResult;
import com.dts.common.core.page.TableDataInfo;
import com.dts.yjnb.service.domain.Category;
import com.dts.yjnb.service.domain.Product;
import com.dts.yjnb.service.domainDto.ProductDTO;
import com.dts.yjnb.service.mapper.CategoryMapper;
import com.dts.yjnb.service.service.IProductService;
import com.dts.yjnb.service.service.impl.CategoryServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dts.common.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.util.Map;

/**
 * 产品管理 信息操作处理
 *
 * @author dts
 */
@Api(tags = "app端产品相关接口")
@RestController
@RequestMapping("/nb-app/1.0.1")
@Slf4j
public class appProductController extends BaseController
{
    @Autowired
    private CategoryServiceImpl categoryService;
    @Autowired
    private IProductService productService;

    @PostMapping("/DictService/queryDictDataTree")
    @ApiOperation("查询产品分类字典树")
    public AppResponse queryDictDataTree1()
    {
        log.info("查询产品分类字典树");
        List<Category> categoryList = categoryService.getlist();
        return AppResponse.success(categoryList);
    }

    /**
     * 分页查询农场产品列表
     *
     * @param productDTO
     * @return 产品分页列表
     */
    @PostMapping("/FarmProduceService/pageAppFarmProduce")
    @ApiOperation("分页查询农场产品")
    public AppPageResult pageAppFarmProduce1(@RequestBody ProductDTO productDTO)
    {
        log.info("分页查询农场产品，参数：{}", productDTO);
        AppPageResult appPageResult = productService.pageAppFarmProduce1(productDTO);
        return appPageResult;
    }
    /**
     * APP端精品推荐列表
     *
     * @param productDTO 查询参数
     * @return 产品分页列表
     */
    @PostMapping("/list")
    @ApiOperation("APP端精品推荐列表")
    public AppPageResult getRecommendList(@RequestBody ProductDTO productDTO)
    {
        log.info("APP端精品推荐列表查询，参数：{}", productDTO);
        AppPageResult appPageResult = productService.getRecommendProductList(productDTO);
        return appPageResult;
    }
    /**
     * APP端根据ID查询产品详情
     *
     * @param id 产品ID
     * @return 产品详情数据
     */
    @GetMapping("/FarmProduceService/getProduceDetail/{id}")
    @ApiOperation("APP端根据ID查询产品详情")
    public AppResponse getProduceDetail(@PathVariable("id") Long id)
    {
        log.info("APP端查询产品详情，ID：{}", id);
        Product product = productService.getByid(id);
        return AppResponse.success(product);
    }
}
